package com.hzy.service.impl;

import com.hzy.dao.sysUser.SysUserMapper;
import com.hzy.pojo.SysUser;
import com.hzy.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Package: com.hzy.service.impl
 * @ClassName: SysUserServiceImpl
 * @Author: 862982795
 * @CreateTime: 2021/07/08 19:17
 * @Description:用户模块业务层实现
 */
@Scope("prototype")
@Transactional
@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService {

    @Autowired //@Resource
    private SysUserMapper sysUserMapper;

    @Override
    public List<SysUser> getList(SysUser sysUser) {
        try {
            return sysUserMapper.selectSysUserList(sysUser);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    public SysUserMapper getSysUserMapper() {
        return sysUserMapper;
    }

    public void setSysUserMapper(SysUserMapper sysUserMapper) {
        this.sysUserMapper = sysUserMapper;
    }

    public boolean add(SysUser sysUser) {
        boolean result = false;
        try {
            if (sysUserMapper.add(sysUser) == 1) {
                result = true;
                //测试事务回滚时。打开注释
//            throw new RuntimeException();F
            }

        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }

        return result;
    }
}

